package com.itheima.juc18.blockingqueue;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @author li
 * 消费者
 */
public class Consumer extends Thread{
    ArrayBlockingQueue<String> blockingQueue;

    public Consumer(ArrayBlockingQueue<String> blockingQueue) {
        this.blockingQueue = blockingQueue;
    }

    @Override
    public void run() {
        while (true) {
            // 不断地从队列中获取面条
            try {
                String food = blockingQueue.take();
                System.out.println(getName() + food);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
